//
//  HEAfterTypeSelectCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/13.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEAfterTypeSelectCell.h"
#import "DLRadioButton.h"

@interface HEAfterTypeSelectCell ()

@property (nonatomic, strong) DLRadioButton *refundMoneyBtn;

@property (nonatomic, strong) DLRadioButton *refundMGBtn;

@property (nonatomic, assign) NSInteger currentIndex;

@end

@implementation HEAfterTypeSelectCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    _refundMoneyBtn = [DLRadioButton new];
    _refundMoneyBtn.tag = 1;
    _refundMoneyBtn.marginWidth = 10;
    _refundMoneyBtn.icon = [UIImage imageNamed:@"check_box_unsel"];
    _refundMoneyBtn.iconSelected = [UIImage imageNamed:@"check_box_sel"];
    [_refundMoneyBtn setTitle:@"退款" forState:UIControlStateNormal];
    [_refundMoneyBtn setTitleColor:CNavLightBlackColor forState:UIControlStateNormal];
    _refundMoneyBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _refundMoneyBtn.titleLabel.font = DYFont(15);
    [_refundMoneyBtn addTarget:self action:@selector(radioSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_refundMoneyBtn];
    
    [_refundMoneyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).offset(15);
        make.width.mas_equalTo([@"退款" widthForFont:DYFont(15)] + 40);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
    
    _refundMoneyBtn.selected = YES;
    _currentIndex = 1;
    
    _refundMGBtn = [DLRadioButton new];
    _refundMGBtn.tag = 3;
    _refundMGBtn.marginWidth = 10;
    _refundMGBtn.icon = [UIImage imageNamed:@"check_box_unsel"];
    _refundMGBtn.iconSelected = [UIImage imageNamed:@"check_box_sel"];
    [_refundMGBtn setTitle:@"退款退货" forState:UIControlStateNormal];
    [_refundMGBtn setTitleColor:CNavLightBlackColor forState:UIControlStateNormal];
    _refundMGBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _refundMGBtn.titleLabel.font = DYFont(15);
    [_refundMGBtn addTarget:self action:@selector(radioSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_refundMGBtn];
    
    [_refundMGBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.left.equalTo(_refundMoneyBtn.mas_right).offset(20);
        make.width.mas_equalTo([@"退款退货" widthForFont:DYFont(15)] + 40);
    }];
    
    NSMutableArray *otherButtons = [NSMutableArray new];
    [otherButtons addObject:_refundMGBtn];
    _refundMoneyBtn.otherButtons = otherButtons;
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    
    self.formModel.as_type = _currentIndex;
}

- (void)radioSelectedButton:(DLRadioButton *)radioButton {
    
    NSInteger index = radioButton.tag;
    _currentIndex = index;
    self.formModel.as_type = index;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
